import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '../components/Login.vue'
const Login = () =>
  import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/Login.vue')
// import Home from '../components/Home.vue'
const Home = () =>
  import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/Home.vue')
// import Welcome from '../components/Welcome.vue'
const Welcome = () =>
  import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/Welcome.vue')
// import Users from '../components/Users/Users.vue'
const Users = () =>
  import(/* webpackChunkName: "Users" */ '../components/Users/Users.vue')
// import Rights from '../components/power/Rights.vue'
const Rights = () =>
  import(/* webpackChunkName: "Power" */ '../components/power/Rights.vue')
// import Roles from '../components/power/Roles.vue'
const Roles = () =>
  import(/* webpackChunkName: "Users" */ '../components/power/Roles.vue')
// import Categories from '../components/Goods/Categories.vue'
const Categories = () =>
  import(/* webpackChunkName: "Goods" */ '../components/Goods/Categories.vue')
// import Params from '../components/Goods/Params.vue'
const Params = () =>
  import(/* webpackChunkName: "Goods" */ '../components/Goods/Params.vue')
// import GoodsList from '../components/Goods/List.vue'
const GoodsList = () =>
  import(/* webpackChunkName: "Goods" */ '../components/Goods/List.vue')
// import Add from '../components/Goods/Add.vue'
const Add = () =>
  import(/* webpackChunkName: "Goods" */ '../components/Goods/Add.vue')
// import Order from '../components/Order/Order.vue'
const Order = () =>
  import(/* webpackChunkName: "Order" */ '../components/Order/Order.vue')
// import Repory from '../components/Repory/Repory.vue'
const Repory = () =>
  import(/* webpackChunkName: "Repory" */ '../components/Repory/Repory.vue')


Vue.use(VueRouter)

const routes = [
  {path:'/',redirect:'/login' },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    redirect:'/welcome',
    children:[
      {path:'/Welcome',component:Welcome},
      {path:'/Users',component:Users},
      {path:'/Rights',component:Rights},
      {path:'/Roles',component:Roles},
      {path:'/Categories',component:Categories},
      {path:'/Params',component:Params},
      {path:'/Goods',component:GoodsList},
      {path:'/goods/Add',component:Add},
      {path:'/Orders',component:Order},
      {path:'/reports',component:Repory},
    ]
  },
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{
  if (to.path === '/login') {
    return next();
  }
  const token = sessionStorage.getItem("token")
  if (!token) {
    next('/login')
  }
  next()
})

export default router
